<extend name="Common/base" />
<block name="content">
<style>
        .auth-success {
            display: inline;
            padding: 0.4em .6em .3em;
            font-size: 75%;
            font-weight: bold;
            line-height: 1;
            color: #fff;
            text-align: center;
            white-space: nowrap;
            vertical-align: baseline;
            border-radius: .25em;
            background-color: #5cb85c;
            float: left;
            margin-top: -45px;
            margin-left: 10%;
        }
        .auth-error{
            display: inline;
            padding: 0.4em .6em .3em;
            font-size: 75%;
            font-weight: bold;
            line-height: 1;
            color: #fff;
            text-align: center;
            white-space: nowrap;
            vertical-align: baseline;
            border-radius: .25em;
            background-color: #b82927;
            float: left;
            margin-top: -45px;
            margin-left: 10%;
        }

    </style>
<div class="col-md-10">
    <div class="row">
        <div class="navbar navbar-default bootstrap-admin-navbar-thin">
            <ol class="breadcrumb bootstrap-admin-breadcrumb">
                <li>
                    <a href="#">首页</a>
                </li>
                <li>
                    <a href="#">商户中心</a>
                </li>
                <li class="active">商户认证</li>
            </ol>
        </div>
    </div>
</div>

<div class="container">
    <!-- left, vertical navbar & content -->
    <div class="row">
        <!-- left, vertical navbar -->
        <include file="Common/leftmenu" />

        <!-- content -->
        <div class="col-md-10">
            <div class="row">
                <div class="panel panel-default bootstrap-admin-no-table-panel">
                    <div class="panel-heading">
                        <div class="text-muted bootstrap-admin-box-title">商户  》》 {$member_info['company_name']}</div>
                    </div>
                    <div class="bootstrap-admin-no-table-panel-content bootstrap-admin-panel-content collapse in">
                            <fieldset>
                                <legend>公司认证</legend>
                                <form action="{:U('BusinessCenter/companyauth')}" method="post" class="form-horizontal" id="mysubfrom" enctype="multipart/form-data">

                                    <div class="form-group">
                                        <label class="col-lg-2 control-label" ><span style="color:red">* </span>姓名：</label>
                                        <div class="col-lg-6">
                                            <input class="form-control" readonly="readonly" datatype="*" value="{$user['contacts']}" name="contacts" errormsg="法人姓名不能为空" nullmsg="法人姓名不能为空" type="text" >
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 control-label"><span style="color:red">* </span>联系方式：</label>
                                        <div class="col-lg-6">
                                            <input class="form-control" readonly="readonly" datatype="*" value="{$user['mobile']}" name="mobile" errormsg="联系方式不能为空" nullmsg="联系方式不能为空" type="text" >
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 control-label" ><span style="color:red">* </span>公司名称：</label>
                                        <div class="col-lg-6">
                                            <input class="form-control" readonly="readonly" name="company_name" value="{$user['company_name']}" datatype="*" nullmsg="公司名不能为空" type="text">
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="col-lg-2 control-label"><span style="color:red">* </span>营业执照：</label>
                                        <div class="col-lg-6">
                                            <input class="form-control" id="img1" onchange="submitImgForm(this)" name="license" value="" datatype="*" nullmsg="营业执照不能为空" type="file">
                                            <input type="hidden" id="license" name="license" value="{$user['license_url']}"/>
                                        </div>
                                        <img tag="show_photo_upload_img1" src="{$user['license_url']}" alt=""/>
                                    </div>

                                    <div class="form-group">
                                        <label class="col-lg-2 control-label" ><span style="color:red">* </span>银行开户许可证：</label>
                                        <div class="col-lg-6">
                                            <input class="form-control" id="img2" onchange="submitImgForm(this)" name="certificate" value="" datatype="*" nullmsg="银行开户许可证不能为空" type="file">
                                            <input type="hidden" id="certificate" name="certificate" value="{$user['certificate_url']}"/>
                                        </div>
                                        <img tag="show_photo_upload_img2" src="{$user['certificate_url']}" alt=""/>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 control-label" >生产许可证：</label>
                                        <div class="col-lg-6">
                                            <input class="form-control" id="img3" onchange="submitImgForm(this)" name="permit" value="" datatype="*" nullmsg="生产许可证不能为空" type="file">
                                            <input type="hidden" id="permit" name="permit" value="{$user['permit_url']}"/>
                                        </div>
                                        <img tag="show_photo_upload_img3" src="{$user['permit_url']}" alt=""/>
                                    </div>
                                    <button type="submit" style=" margin-left:25%;" class="btn btn-primary">确认认证</button>
                                </form>

                            </fieldset>
                    </div>
                </div>
            </div>

        </div>
    </div>

</div>

</block>
<block name="script">
<script type="text/javascript">

    function submitImgForm(obj){

        if ($(obj).val() == "") {
            alert("请选择一个图片文件，再点击上传。");
            return;
        }

        var csrf = $("input[name='license']").val();

        var formData=new FormData();
        formData.append("license",csrf);
        formData.append('avatar', $(obj)[0].files[0]);  /*获取上传的图片对象*/
        $.ajax({
            url: '{:U("BusinessCenter/fileUpload")}',
            type: 'POST',
            data: formData,
            contentType: false,
            processData: false,
            success: function (args) {
                console.log(args);  /*服务器端的图片地址*/
                alert(args.error);
                if (obj.id == 'img1'){
                    $("[tag='show_photo_upload_img1']").attr('src',args.img_path);  /*预览图片*/
                    $("#license").val(args.img_path);  /*将服务端的图片url赋值给form表单的隐藏input标签*/
                }
                if (obj.id == 'img2'){
                    $("[tag='show_photo_upload_img2']").attr('src',args.img_path);  /*预览图片*/
                    $("#certificate").val(args.img_path);  /*将服务端的图片url赋值给form表单的隐藏input标签*/
                }
                if (obj.id == 'img3'){
                    $("[tag='show_photo_upload_img3']").attr('src',args.img_path);  /*预览图片*/
                    $("#permit").val(args.img_path);  /*将服务端的图片url赋值给form表单的隐藏input标签*/
                }
            }
        })
    }


    $(function() {
        $('.datepicker').datepicker();
        $('.uniform_on').uniform();
        $('.chzn-select').chosen();
        $('.textarea-wysihtml5').wysihtml5({
            stylesheets: [
                '/public/logistics/vendors/bootstrap-wysihtml5-rails-b3/vendor/assets/stylesheets/bootstrap-wysihtml5/wysiwyg-color.css'
            ]
        });

        $('#rootwizard').bootstrapWizard({
            'nextSelector': '.next',
            'previousSelector': '.previous',
            onNext: function(tab, navigation, index) {
                var $total = navigation.find('li').length;
                var $current = index + 1;
                var $percent = ($current / $total) * 100;
                $('#rootwizard').find('.progress-bar').css('width', $percent + '%');
                // If it's the last tab then hide the last button and show the finish instead
                if ($current >= $total) {
                    $('#rootwizard').find('.pager .next').hide();
                    $('#rootwizard').find('.pager .finish').show();
                    $('#rootwizard').find('.pager .finish').removeClass('disabled');
                } else {
                    $('#rootwizard').find('.pager .next').show();
                    $('#rootwizard').find('.pager .finish').hide();
                }
            },
            onPrevious: function(tab, navigation, index) {
                var $total = navigation.find('li').length;
                var $current = index + 1;
                var $percent = ($current / $total) * 100;
                $('#rootwizard').find('.progress-bar').css('width', $percent + '%');
                // If it's the last tab then hide the last button and show the finish instead
                if ($current >= $total) {
                    $('#rootwizard').find('.pager .next').hide();
                    $('#rootwizard').find('.pager .finish').show();
                    $('#rootwizard').find('.pager .finish').removeClass('disabled');
                } else {
                    $('#rootwizard').find('.pager .next').show();
                    $('#rootwizard').find('.pager .finish').hide();
                }
            },
            onTabShow: function(tab, navigation, index) {
                var $total = navigation.find('li').length;
                var $current = index + 1;
                var $percent = ($current / $total) * 100;
                $('#rootwizard').find('.bar').css({width: $percent + '%'});
            }
        });
        $('#rootwizard .finish').click(function() {
            alert('Finished!, Starting over!');
            $('#rootwizard').find('a[href*=\'tab1\']').trigger('click');
        });
    });
</script>
</block>